/*!
 * DOMEffects 0.2.6, Copyright (c) 2008 Pelle Wessman, <http://code.google.com/p/domeffects>, MIT Style License.
 */
/*extern DOMAssistant */
/**
 * @fileOverview Shows and hides elements, requires DOMEffects
 * @name DOMEffects Show and Hide
 */

/** @scope DOMAssistant */
DOMAssistant.attach({
	/**
	 * Shows an element
	 * @param  {object}   [options]     The options
	 * @config {integer}  [duration]    Amount of time in milliseconds that the element will be animated, default 1.5 second. If 0 the animation will happen immediatly.
	 * @config {function} [easing]      A function describing an easing equation, default linear
	 * @config {function} [callback]    A function to be called once the element has been hidden
	 * @return {object}                 Returns the element to enable chaining
	 * @example $('div').show(); //Shows the element with default options
	 * @example $('div').show({duration: 0}); //Sets the element as shown immediately without animating the process
	 * @example //Easing function
	 * function easeExpoOut(timediff, base, change, duration) {
	 * 	return (timediff==duration) ?
	 * 	       base+change :
	 * 	       change * (-Math.pow(2, -10 * timediff/duration) + 1) + base;
	 * }
	 * //Show-call with many options set
	 * $('div').show({duration: 400, transition: easeExpoOut, callback: function() {
	 * 	console.log('Element shown!');
	 * }});
	 */
	show: function(options){
		options = options ? options : {};
		var elem = $$(this);
		if (options.duration === 0) {
			elem.setStyle(DOMEffects.getOpacityRule(1));
		} else {
			var aniOptions = {};

			aniOptions.duration = options.duration;
			aniOptions.easing   = options.easing;
			aniOptions.callback = options.callback;

			elem.animate({
				opacity: {
					value: 1,
					unit: ''
				}
			}, aniOptions);
		}
		return elem;
	},

	/**
	 * Hides an element
	 * @param  {object}   [options]     The options
	 * @config {boolean}  [remove]      If the element should be removed after it has been hidden, can't be combined with callback
	 * @config {integer}  [duration]    Amount of time in milliseconds that the element will be animated. If 0 the animation will happen immediatly.
	 * @config {function} [easing]      A function describing an easing equation
	 * @config {function} [callback]    A function to be called once the element has been hidden, can't be combined with remove
	 * @return {object}                 Returns the element to enable chaining
	 * @example $('div').hide(); //Hides the element with default options
	 * @example $('div').show({duration: 0}); //Sets the element as hidden immediately without animating the process
	 * @example //Easing function
	 * function easeExpoOut(timediff, base, change, duration) {
	 * 	return (timediff==duration) ?
	 * 	       base+change :
	 * 	       change * (-Math.pow(2, -10 * timediff/duration) + 1) + base;
	 * }
	 * //Hide-call with many options set
	 * $('div').show({remove: true, duration: 400, transition: easeExpoOut);
	 */
	hide: function(options){
		options = options ? options : {};
		var elem = $$(this);
		if (options.duration === 0) {
			elem.setStyle(DOMEffects.getOpacityRule(0));
		} else {
			var aniOptions = {};

			aniOptions.duration = options.duration;
			aniOptions.easing   = options.easing;
			aniOptions.callback = options.remove ? function(){elem.remove();} : options.callback;

			elem.animate({
				opacity: {
					value: 0,
					unit: ''
				}
			}, aniOptions);
		}
		return elem;
	}
});